import 'package:boss/models/store_table.dart';
import 'package:json_annotation/json_annotation.dart';

part 'book_info_list_data.g.dart';

@JsonSerializable()
class BookInfoListData extends Object {
  @JsonKey(name: 'total')
  int total;

  @JsonKey(name: 'totalPage')
  int totalPage;

  @JsonKey(name: 'items')
  List<BookInfo> items;

  BookInfoListData(
    this.total,
    this.totalPage,
    this.items,
  );

  factory BookInfoListData.fromJson(Map<String, dynamic> srcJson) => _$BookInfoListDataFromJson(srcJson);

  Map<String, dynamic> toJson() => _$BookInfoListDataToJson(this);
}

@JsonSerializable()
class BookInfo extends Object {
  static const String MEAL_LUNCH = 'lunch';
  static const String MEAL_DINNER = 'dinner';
  static const String MEAL_SUPPER = 'supper';

  static const String SEX_MAN = 'Mr';
  static const String SEX_WOMAN = 'Ms';

  static const STATUS_BEGIN = 'begin';
  static const STATUS_CANCEL = 'cancel';
  static const STATUS_END = 'end';

  static Map<String, String> statusMap = {
    STATUS_BEGIN: '已预订',
    STATUS_END: '客到',
    STATUS_CANCEL: '已取消',
  };

  @JsonKey(name: 'id')
  int id;

  @JsonKey(name: 'storeId')
  int storeId;

  @JsonKey(name: 'meal')
  String meal;

  @JsonKey(name: 'bookDate')
  String bookDate;

  @JsonKey(name: 'week')
  String week;

  @JsonKey(name: 'phone')
  String phone;

  @JsonKey(name: 'customerName')
  String customerName;

  @JsonKey(name: 'title')
  String title;

  @JsonKey(name: 'arriveTime')
  String arriveTime;

  @JsonKey(name: 'personNum')
  int personNum;

  @JsonKey(name: 'waiterId')
  int waiterId;

  @JsonKey(name: 'waiterName')
  String waiterName;

  @JsonKey(name: 'remarks')
  String remarks;

  @JsonKey(name: 'bookReason')
  String bookReason;

  @JsonKey(name: 'tableNum')
  int tableNum;

  @JsonKey(name: 'status')
  String status;

  @JsonKey(name: 'bookSource')
  String bookSource;

  @JsonKey(name: 'creator')
  int creator;

  @JsonKey(name: 'updater')
  int updater;

  @JsonKey(name: 'ctime')
  String ctime;

  @JsonKey(name: 'utime')
  String utime;

  @JsonKey(name: 'tableList')
  List<StoreTable> tableList;

  String get tableName => tableList.map((item) => '${item.areaName}-${item.tableName}').join(',');

  BookInfo(
    this.id,
    this.storeId,
    this.meal,
    this.bookDate,
    this.week,
    this.phone,
    this.customerName,
    this.title,
    this.arriveTime,
    this.personNum,
    this.waiterId,
    this.waiterName,
    this.remarks,
    this.bookReason,
    this.tableNum,
    this.status,
    this.bookSource,
    this.creator,
    this.updater,
    this.ctime,
    this.utime,
    this.tableList,
  );

  factory BookInfo.fromJson(Map<String, dynamic> srcJson) => _$BookInfoFromJson(srcJson);

  Map<String, dynamic> toJson() => _$BookInfoToJson(this);
}
